home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / findqr.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  3KB  |  87 lines

  1. /*****************************************************************************
  2.  
  3.     FindQR()
  4.  
  5.     This function "finds" a q-register.  CBfPtr points to the first
  6. character of the q-register name.  If it is a period (q-register is local to
  7. this macro level),  then CBfPtr is incremented to point to the next
  8. character and,  if this is the first use of a local q-register in this macro
  9. level,  then memory for a local q-register table is allocated.
  10.  
  11.     This function sets up the QR global variable.
  12.  
  13. *****************************************************************************/
  14.  
  15. #include "zport.h"        /* define portability identifiers */
  16. #include "tecoc.h"        /* define general identifiers */
  17. #include "defext.h"        /* define external global variables */
  18. #include "deferr.h"        /* define identifiers for error messages */
  19. #include "chmacs.h"        /* define character processing macros */
  20.  
  21. DEFAULT FindQR()        /* find q-register index */
  22. {
  23.     WORD    i;
  24.     BOOLEAN    LocalQ;
  25.     WORD    QIndex;
  26.     unsigned char QName;
  27.  
  28. /*
  29.  * If it's a local q-register name (starts with a dot), remember and move on.
  30.  */
  31.     DBGFEN(3,"FindQR",NULL);
  32.     LocalQ = (*CBfPtr == '.');            /* if local q-register */
  33.     if (LocalQ) {                /* if local q-register name */
  34.         if (IncCBP() == FAILURE) {        /* move to next character */
  35.         DBGFEX(3,DbgFNm,"FAILURE, IncCBP() failed");
  36.         return FAILURE;
  37.     }
  38.     }
  39.  
  40. /*
  41.  * Get the index into the QRgstr array into i.
  42.  */
  43.     QName = *CBfPtr;
  44.     if (Is_Upper(QName)) {
  45.         i = 'A' - 10;                /* QRgStr[10..35] */
  46.     } else if (Is_Lower(QName)) {
  47.     i = 'a' - 10;                /* QRgstr[10..35] */
  48.     } else if (Is_Digit(QName)) {
  49.     i = '0';                /* QRgstr[0..9] */
  50.     } else {
  51.         ErrChr(ERR_IQN, QName);
  52.     DBGFEX(3,DbgFNm,"FAILURE, illegal Q-register name");
  53.     return FAILURE;
  54.     }
  55.  
  56. /*
  57.  * Get a pointer to the structure into QR.
  58.  */
  59.     QIndex = QName - i;                /* index into QRgstr[] */
  60.     if (LocalQ) {                /* if local q-register */
  61.         if (MStTop < 0) {            /* if not in a macro */
  62.         QR = &QRgstr[QIndex+36];        /* use QRgstr[36..71] */
  63.     } else {                /* else (we're in a macro) */
  64.         WORD TMIndx;
  65.         QRptr QRp;
  66.         for (TMIndx=MStTop; TMIndx>0; TMIndx--) {
  67.         if (MStack[TMIndx].QRgstr != NULL) {
  68.             QRp = MStack[TMIndx].QRgstr;
  69.             break;
  70.         }
  71.         }
  72.         QR = (TMIndx != 0)            /* if we found one */
  73.         ? &QRp[QIndex]            /* use the one we found */ 
  74.         : &QRgstr[QIndex+36];        /* else use main level ones */
  75.     }
  76.     } else {
  77.         QR = &QRgstr[QIndex];
  78.     }
  79.  
  80. #if DEBUGGING
  81.     sprintf(DbgSBf,"SUCCESS, %sQIndex = %d (QName = '%c')",
  82.         (LocalQ) ? "local " : "", QIndex, QName);
  83.     DBGFEX(3,DbgFNm,DbgSBf);
  84. #endif
  85.     return SUCCESS;
  86. }
  87.